<template>
  <div class="app">
    <div class="user" v-if="!this.$store.state.isAdmin">
      <farmer-header class="header"></farmer-header>
      <router-view class="view"></router-view>
      <farmer-footer class="footer"></farmer-footer>
    </div>
    <div class="admin" v-else>
      <router-view class="view"></router-view>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
// 导入组件
import myHeader from '@/components/Header'
import myFooter from '@/components/Footer'

Vue.component('farmer-header', myHeader)
Vue.component('farmer-footer', myFooter)

export default {
  data () {
    return {
      isAdmin: false
    }
  },
  watch: {
    // 判断浏览器显示页面->普通用户和管理员
    // 限制管理员跳转用户页面
    $route (to, from) {
      if (this.$store.state.isAdmin) {
        if (from.matched[0].path === '/admin' && to.matched[0].path === '/admin') {
          return
        }
        this.$router.push('/admin')
      }
    }
  },
  mounted () {
  }
}
</script>

<style scoped>
.user {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-content: center;
  min-height: 100vh;
  width: 100%;
}
.header {
  min-height: 44px;
  display: flex;
  margin-top: 15px;
  flex-direction: row-reverse;
  justify-content: flex-start;
  width: 100%;
}
.view {
  /* height: auto; */
  /* min-height: 90vh; */
  /* min-height: 90vh; */
  /* min-height: 90vh;
  max-height: 90vh; */
  animation: 0.2s changeView ease-in;
}
@keyframes changeView {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
.footer {
  /* height: 0px; */
  bottom: 0;
}
</style>
